Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for Optional JSONEncoding errors #1317

Merged
merged 3 commits into from
Jul 17, 2020
Merged

Conversation

designatednerd
Copy link
Contributor

This is basically a band-aid on #1305 and similar bugs, which could occur when using a custom JSON scalar and trying to persist it to the cache. If the type of the typealiased JSON was [String: Any?], which is expected, the as JSONEncodable would fail to recognize several types that have that conformance in an extension, and those types need to be unwrapped manually.

This is a band-aid rather than a permanent fix because once I can get the Swift codegen stuff going again, I'm going to rip all this JSONEncodable stuff out in favor of a Codable solution (you can see a preview of the more flexible part of this in the JSON type I'm using in the Codegen lib).

But that's gonna be a hot minute, so band-aid it is!


// WORKAROUND: For reasons I don't totally understand, when the underlying type is `Any`,
// even though all of these conform to `JSONEncodable`, the `as JSONEncodable` above
// fails, and we need to handle them individually.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone's got any bright ideas why this fails, I'm all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant